// ml:run = $bin < input
#include <iostream>
#include <deque>
#include <string>
#include <algorithm>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <set>

int const maxn = 300007;
int tot[maxn];
int last[maxn];
int sum;
int n, q;

int main()
{
    std::ios_base::sync_with_stdio(false);
    std::cin >> n >> q;
    using pair = std::pair<int, int>;
    std::deque<pair> dq;
    int len = 0;
    for (int i = 0; i < q; i++) {
        int opt, x; std::cin >> opt >> x;
        if (opt == 1) {
            sum++; tot[x]++;
            dq.push_back({++len, x});
            while (!dq.empty()) {
                auto now = dq.front();
                if (now.first <= last[now.second]) dq.pop_front();
                else break;
            }
        } else if (opt == 2) {
            sum -= tot[x]; tot[x] = 0;
            last[x] = len;
            while (!dq.empty()) {
                auto now = dq.front();
                if (now.first <= last[now.second]) dq.pop_front();
                else break;
            }
        } else {
            while (!dq.empty()) {
                auto now = dq.front();
                if (now.first <= last[now.second]) dq.pop_front();
                else if (now.first <= x) {
                    sum--;
                    tot[now.second]--;
                    dq.pop_front();
                } else break;
            }
        }
        std::cout << sum << "\n";
    }
}

